/**********************************************************************************************************
** 驱动文件：	ups-UPS001.c
** 驱动类型：	ups
** 设备名称：	UPS监测
** 设备型号：	UPS001
** 设备品牌：	未知
** 设备协议：	RS232通讯协议
** 驱动描述：	适用于UPS三进三出高频机，协议指令为QWS、QWF、QMOD、Q3PV、Q3PC、Q3OV、Q3OC、Q3YV、Q3YC、Q3LD
** 生成日期：	2020-04-23 23:17:37
**********************************************************************************************************/
#include "Includes.h"


/**********************************************************************************************************
* 定义设备数据点变量结构
**********************************************************************************************************/
typedef struct{
	Var UPSMode;								//UPS模式
	Var inputUA;								//A相输入电压
	Var inputUB;								//B相输入电压
	Var inputUC;								//C相输入电压
	Var inputIA;								//A相输入电流
	Var inputIB;								//B相输入电流
	Var inputIC;								//C相输入电流
	Var outputUA;								//A相输出电压
	Var outputUB;								//B相输出电压
	Var outputUC;								//C相输出电压
	Var outputIA;								//A相输出电流
	Var outputIB;								//B相输出电流
	Var outputIC;								//C相输出电流
	Var bypassUA;								//A相旁路电压
	Var bypassUB;								//B相旁路电压
	Var bypassUC;								//C相旁路电压
	Var bypassIA;								//A相旁路电流
	Var bypassIB;								//B相旁路电流
	Var bypassIC;								//C相旁路电流
	Var loadRateA;								//A相负载率
	Var loadRateB;								//B相负载率
	Var loadRateC;								//C相负载率
	Var PositiveBatteryVoltage;					//正极电池组电压
	Var PositiveBatteryCapacity;				//正极电池组容量
	Var PositiveBatteryRemainTime;				//正极电池组剩余时间
	Var NegativeBatteryVoltage;					//负极电池组电压
	Var NegativeBatteryCapacity;				//负极电池组容量
	Var NegativeBatteryRemainTime;				//负极电池组剩余时间
	Var BatteryOpen;							//电池未接报警
	Var IPNloss;								//输入N线丢失
	Var IPSiteFail;								//输入零火反接
	Var LinePhaseError;							//市电相序错误
	Var BypassPhaseError;						//旁路相序错误
	Var BatteryOverCharge;						//电池过冲
	Var BatteryLow;								//电池低压
	Var OverloadWarning;						//过载报警
	Var FanFail;								//风扇故障
	Var EPOActive;								//EPO生效
	Var OverTemperature;						//高温报警
	Var ChargerFail;							//充电器故障
	Var L1IPFuseFail;							//L1输入保险开路
	Var L2IPFuseFail;							//L2输入保险开路
	Var L3IPFuseFail;							//L3输入保险开路
	Var CANCommunicationError;					//CAN总线通讯报警
	Var BatteryFuseBroken;						//电池保险开路
	Var P1CutOffPreAlarm;						//P1切断预警
	Var BatteryReplaceWarn;						//电池更换告警
	Var MaintainBypassSwitchOffAlarm;			//维修旁路开路报警
	Var MainsFailure;							//市电异常
	Var BypassUnstable;							//旁路异常
	Var BatteryDischargerOverly;				//电池过放报警
}Data_Struct;									//定义变量结构


/**********************************************************************************************************
* 设备数据点变量属性声明
**********************************************************************************************************/
const static Var_Property_Def var_attr[] = {
	{
		OCTSTR,
		0,
		READONLY,
		"UPSMode",
		"UPS模式",
		"",
		"UPS模式：0-初始化；1-待机状态；2-旁路状态；3-市电状态；4-电池状态；5-电池自检状态；6-逆变模式；7-经济模式；8-关机模式；9-故障模式",
		0,
		0,
		"",
		"",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"inputUA",
		"A相输入电压",
		"V",
		"A相输入电压",
		0,
		0,
		"A相输入电压过高",
		"A相输入电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"inputUB",
		"B相输入电压",
		"V",
		"B相输入电压",
		0,
		0,
		"B相输入电压过高",
		"B相输入电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"inputUC",
		"C相输入电压",
		"V",
		"C相输入电压",
		0,
		0,
		"C相输入电压过高",
		"C相输入电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"inputIA",
		"A相输入电流",
		"A",
		"A相输入电流",
		0,
		0,
		"A相输入电流过高",
		"A相输入电流过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"inputIB",
		"B相输入电流",
		"A",
		"B相输入电流",
		0,
		0,
		"B相输入电流过高",
		"B相输入电流过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"inputIC",
		"C相输入电流",
		"A",
		"C相输入电流",
		0,
		0,
		"C相输入电流过高",
		"C相输入电流过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputUA",
		"A相输出电压",
		"V",
		"A相输出电压",
		0,
		0,
		"A相输出电压过高",
		"A相输出电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputUB",
		"B相输出电压",
		"V",
		"B相输出电压",
		0,
		0,
		"B相输出电压过高",
		"B相输出电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputUC",
		"C相输出电压",
		"V",
		"C相输出电压",
		0,
		0,
		"C相输出电压过高",
		"C相输出电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputIA",
		"A相输出电流",
		"A",
		"A相输出电流",
		0,
		0,
		"A相输出电流过高",
		"A相输出电流过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputIB",
		"B相输出电流",
		"A",
		"B相输出电流",
		0,
		0,
		"B相输出电流过高",
		"B相输出电流过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputIC",
		"C相输出电流",
		"A",
		"C相输出电流",
		0,
		0,
		"C相输出电流过高",
		"C相输出电流过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"bypassUA",
		"A相旁路电压",
		"V",
		"A相旁路电压",
		0,
		0,
		"A相旁路电压过高",
		"A相旁路电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"bypassUB",
		"B相旁路电压",
		"V",
		"B相旁路电压",
		0,
		0,
		"B相旁路电压过高",
		"B相旁路电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"bypassUC",
		"C相旁路电压",
		"V",
		"C相旁路电压",
		0,
		0,
		"C相旁路电压过高",
		"C相旁路电压过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"bypassIA",
		"A相旁路电流",
		"A",
		"A相旁路电流",
		0,
		0,
		"A相旁路电流过高",
		"A相旁路电流过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"bypassIB",
		"B相旁路电流",
		"A",
		"B相旁路电流",
		0,
		0,
		"B相旁路电流过高",
		"B相旁路电流过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"bypassIC",
		"C相旁路电流",
		"A",
		"C相旁路电流",
		0,
		0,
		"C相旁路电流过高",
		"C相旁路电流过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"loadRateA",
		"A相负载率",
		"%",
		"A相负载率",
		0,
		0,
		"A相负载率过高",
		"A相负载率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"loadRateB",
		"B相负载率",
		"%",
		"B相负载率",
		0,
		0,
		"B相负载率过高",
		"B相负载率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"loadRateC",
		"C相负载率",
		"%",
		"C相负载率",
		0,
		0,
		"C相负载率过高",
		"C相负载率过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"PositiveBatteryVoltage",
		"正极电池组电压",
		"V",
		"正极电池组电压",
		0,
		0,
		"正极电池组电压过高",
		"正极电池组电压过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"PositiveBatteryCapacity",
		"正极电池组容量",
		"%",
		"正极电池组容量",
		0,
		0,
		"正极电池组容量过高",
		"正极电池组容量过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"PositiveBatteryRemainTime",
		"正极电池组剩余时间",
		"分",
		"正极电池组剩余时间",
		0,
		0,
		"正极电池组剩余时间过高",
		"正极电池组剩余时间过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"NegativeBatteryVoltage",
		"负极电池组电压",
		"V",
		"负极电池组电压",
		0,
		0,
		"负极电池组电压过高",
		"负极电池组电压过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"NegativeBatteryCapacity",
		"负极电池组容量",
		"%",
		"负极电池组容量",
		0,
		0,
		"负极电池组容量过高",
		"负极电池组容量过低",
		0.000,
		0.000
	},
	{
		INTEGER,
		0,
		READONLY,
		"NegativeBatteryRemainTime",
		"负极电池组剩余时间",
		"分",
		"负极电池组剩余时间",
		0,
		0,
		"负极电池组剩余时间过高",
		"负极电池组剩余时间过低",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryOpen",
		"电池未接报警",
		"",
		"电池未接报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"IPNloss",
		"输入N线丢失",
		"",
		"输入N线丢失",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"IPSiteFail",
		"输入零火反接",
		"",
		"输入零火线反接报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"LinePhaseError",
		"市电相序错误",
		"",
		"市电相序错误",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BypassPhaseError",
		"旁路相序错误",
		"",
		"旁路相序错误",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryOverCharge",
		"电池过冲",
		"",
		"电池过冲报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryLow",
		"电池低压",
		"",
		"电池低压报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"OverloadWarning",
		"过载报警",
		"",
		"过载报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"FanFail",
		"风扇故障",
		"",
		"风扇模组堵转报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"EPOActive",
		"EPO生效",
		"",
		"EPO开关生效",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"OverTemperature",
		"高温报警",
		"",
		"高温报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"ChargerFail",
		"充电器故障",
		"",
		"充电器报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"L1IPFuseFail",
		"L1输入保险开路",
		"",
		"L1输入保险开路报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"L2IPFuseFail",
		"L2输入保险开路",
		"",
		"L2输入保险开路报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"L3IPFuseFail",
		"L3输入保险开路",
		"",
		"L3输入保险开路报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"CANCommunicationError",
		"CAN总线通讯报警",
		"",
		"CAN总线通讯报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryFuseBroken",
		"电池保险开路",
		"",
		"电池保险开路报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"P1CutOffPreAlarm",
		"P1切断预警",
		"",
		"P1切断预警",
		0,
		0,
		"预警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryReplaceWarn",
		"电池更换告警",
		"",
		"电池需要更换告警",
		0,
		0,
		"告警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"MaintainBypassSwitchOffAlarm",
		"维修旁路开路报警",
		"",
		"维修旁路开路报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"MainsFailure",
		"市电异常",
		"",
		"市电电压极度不稳定",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BypassUnstable",
		"旁路异常",
		"",
		"旁路状态不稳定",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryDischargerOverly",
		"电池过放报警",
		"",
		"电池过放报警",
		0,
		0,
		"报警",
		"",
		0.000,
		0.000
	}
};


/**********************************************************************************************************
* 函数名称： static void cmd_fun(short index, int addr, void *data, char *cmd, short *len)
* 函数说明： 生成获取传感器数据指令
* 输入参数： 指令索引，传感器地址，变量结构体指针,以及指令缓存区指针,指令长度
* 返回参数： 无
**********************************************************************************************************/
static void cmd_fun(short index, int addr, void *data, char *cmd, short *len)
{
	switch(index)
	{
		case 0:
			*len = sprintf(cmd,"QMOD\r");
			break;
		case 1:
			*len = sprintf(cmd,"Q3PV\r");
			break;
		case 2:
			*len = sprintf(cmd,"Q3PC\r");
			break;
		case 3:
			*len = sprintf(cmd,"Q3OV\r");
			break;
		case 4:
			*len = sprintf(cmd,"Q3OC\r");
			break;
		case 5:
			*len = sprintf(cmd,"Q3YV\r");
			break;
		case 6:
			*len = sprintf(cmd,"Q3YC\r");
			break;
		case 7:
			*len = sprintf(cmd,"Q3LD\r");
			break;
		case 8:
			*len = sprintf(cmd,"QBV\r");
			break;
		case 9:
			*len = sprintf(cmd,"QNBV\r");
			break;
		case 10:
			*len = sprintf(cmd,"QWS\r");
			break;			
		default:
			break;
	}
}


/**********************************************************************************************************
* 函数名称： static int parse_fun(short index, int addr, void *data, char *buf, short len)
* 函数说明： 解析传感器响应的数据，并写入数据库
* 输入参数： 解析索引,传感器地址，变量结构体指针，以及响应数据缓存取指针，响应数据长度
* 返回参数： 返回解析结果，返回0成功，返回1失败
**********************************************************************************************************/
static int parse_fun(short index, int addr, void *data, char *buf, short len)
{
	Data_Struct 	*d = (Data_Struct*)data;

	buf[len] = '\0';
	if(buf!=NULL && buf[0]=='(' && len>0 && buf[len-1]=='\r')
	{	
		switch(index)
		{
			case 0:		//(M<cr>
				switch(buf[1]){
					case 'P': d->UPSMode.value.str = "初始化";		Set_Var_Status(&d->UPSMode, Normal, NULL) ;break;
					case 'S': d->UPSMode.value.str = "待机状态";	Set_Var_Status(&d->UPSMode, Normal, NULL) ;break;
					case 'Y': d->UPSMode.value.str = "旁路状态";	Set_Var_Status(&d->UPSMode, Normal, NULL) ;break;
					case 'L': d->UPSMode.value.str = "市电状态";	Set_Var_Status(&d->UPSMode, Normal, NULL) ;break;
					case 'B': d->UPSMode.value.str = "电池状态";	Set_Var_Status(&d->UPSMode, Normal, NULL) ;break;
					case 'T': d->UPSMode.value.str = "电池自检状态";Set_Var_Status(&d->UPSMode, Normal, NULL) ;break;
					case 'C': d->UPSMode.value.str = "逆变模式";	Set_Var_Status(&d->UPSMode, Normal, NULL) ;break;
					case 'E': d->UPSMode.value.str = "经济模式";	Set_Var_Status(&d->UPSMode, Normal, NULL) ;break;
					case 'D': d->UPSMode.value.str = "关机模式";	Set_Var_Status(&d->UPSMode, Alarm, NULL) ;break;
					case 'F': d->UPSMode.value.str = "故障模式";	Set_Var_Status(&d->UPSMode, Alarm, NULL) ;break;
					default: break;
				}
				break;
			case 1:		//(220.2 215.3 222.1 381.4 373.2 384.6<cr>
				d->inputUA.value.fnum 	= atof(buf+1);
				d->inputUB.value.fnum 	= atof(buf+7);
				d->inputUC.value.fnum 	= atof(buf+13);				
				break;
			case 2:		//(045.2 044.3 045.1<cr>
				d->inputIA.value.fnum 	= atof(buf+1);
				d->inputIB.value.fnum 	= atof(buf+7);
				d->inputIC.value.fnum 	= atof(buf+13);					
				break;
			case 3:		//(220.2 215.3 222.1 381.4 373.2 384.6<cr>
				d->outputUA.value.fnum 	= atof(buf+1);
				d->outputUB.value.fnum 	= atof(buf+7);
				d->outputUC.value.fnum 	= atof(buf+13);					
				break;
			case 4:		//(045.2 044.3 045.1<cr>
				d->outputIA.value.fnum 	= atof(buf+1);
				d->outputIB.value.fnum 	= atof(buf+7);
				d->outputIC.value.fnum 	= atof(buf+13);	
				break;
			case 5:		//(220.2 215.3 222.1 381.4 373.2 384.6<cr>
				d->bypassUA.value.fnum 	= atof(buf+1);
				d->bypassUB.value.fnum 	= atof(buf+7);
				d->bypassUC.value.fnum 	= atof(buf+13);				
				break;
			case 6:		//(045.2 044.3 045.1<cr>
				d->bypassIA.value.fnum 	= atof(buf+1);
				d->bypassIB.value.fnum 	= atof(buf+7);
				d->bypassIC.value.fnum 	= atof(buf+13);	
				break;
			case 7:		//(045.2 042.3 047.0 050.1<cr>
				d->loadRateA.value.fnum 	= atof(buf+1);
				d->loadRateB.value.fnum 	= atof(buf+7);
				d->loadRateC.value.fnum 	= atof(buf+13);	
				break;
			case 8:		//(RRR.R NN MM CCC TTTTT<cr>
				d->PositiveBatteryVoltage.value.fnum 	= atof(buf+1);
				d->PositiveBatteryCapacity.value.inum 	= atoi(buf+13);
				d->PositiveBatteryRemainTime.value.inum = atoi(buf+17);	
				break;
			case 9:		//(RRR.R NN MM CCC TTTTT<cr>
				d->NegativeBatteryVoltage.value.fnum 	= atof(buf+1);
				d->NegativeBatteryCapacity.value.inum 	= atoi(buf+13);
				d->NegativeBatteryRemainTime.value.inum = atoi(buf+17);					
				break;
			case 10:	//(a0a1……a62a63<cr>
				d->BatteryOpen.value.str						= buf[1]=='1'?"告警":"正常";
				Set_Var_Status(&d->BatteryOpen,			  		  buf[1]=='1'?Alarm:Normal, NULL);
				d->IPNloss.value.str							= buf[2]=='1'?"告警":"正常";
				Set_Var_Status(&d->IPNloss,		  				  buf[2]=='1'?Alarm:Normal, NULL);
				d->IPSiteFail.value.str							= buf[3]=='1'?"告警":"正常";
				Set_Var_Status(&d->IPSiteFail,		 	 		  buf[3]=='1'?Alarm:Normal, NULL);
				d->LinePhaseError.value.str						= buf[4]=='1'?"告警":"正常";
				Set_Var_Status(&d->LinePhaseError,		  		  buf[4]=='1'?Alarm:Normal, NULL);
				d->BypassPhaseError.value.str					= buf[5]=='1'?"告警":"正常";
				Set_Var_Status(&d->BypassPhaseError,		  	  buf[5]=='1'?Alarm:Normal, NULL);
				d->BatteryOverCharge.value.str					= buf[7]=='1'?"告警":"正常";
				Set_Var_Status(&d->BatteryOverCharge,		  	  buf[7]=='1'?Alarm:Normal, NULL);
				d->BatteryLow.value.str							= buf[8]=='1'?"告警":"正常";
				Set_Var_Status(&d->BatteryLow,		  			  buf[8]=='1'?Alarm:Normal, NULL);
				d->OverloadWarning.value.str					= buf[9]=='1'?"告警":"正常";
				Set_Var_Status(&d->OverloadWarning,		  		  buf[9]=='1'?Alarm:Normal, NULL);
				d->FanFail.value.str							= buf[10]=='1'?"告警":"正常";
				Set_Var_Status(&d->FanFail,		  				  buf[10]=='1'?Alarm:Normal, NULL);
				d->EPOActive.value.str							= buf[11]=='1'?"告警":"正常";
				Set_Var_Status(&d->EPOActive,		  			  buf[11]=='1'?Alarm:Normal, NULL);
				d->OverTemperature.value.str					= buf[13]=='1'?"告警":"正常";
				Set_Var_Status(&d->OverTemperature,		  		  buf[13]=='1'?Alarm:Normal, NULL);
				d->ChargerFail.value.str						= buf[14]=='1'?"告警":"正常";
				Set_Var_Status(&d->ChargerFail,		  			  buf[14]=='1'?Alarm:Normal, NULL);
				d->L1IPFuseFail.value.str						= buf[16]=='1'?"告警":"正常";
				Set_Var_Status(&d->L1IPFuseFail,		  		  buf[16]=='1'?Alarm:Normal, NULL);
				d->L2IPFuseFail.value.str						= buf[17]=='1'?"告警":"正常";
				Set_Var_Status(&d->L2IPFuseFail,		  		  buf[17]=='1'?Alarm:Normal, NULL);
				d->L3IPFuseFail.value.str						= buf[18]=='1'?"告警":"正常";
				Set_Var_Status(&d->L3IPFuseFail,		  		  buf[18]=='1'?Alarm:Normal, NULL);
				d->CANCommunicationError.value.str				= buf[25]=='1'?"告警":"正常";
				Set_Var_Status(&d->CANCommunicationError,		  buf[25]=='1'?Alarm:Normal, NULL);
				d->BatteryFuseBroken.value.str					= buf[53]=='1'?"告警":"正常";
				Set_Var_Status(&d->BatteryFuseBroken,		  	  buf[53]=='1'?Alarm:Normal, NULL);
				d->P1CutOffPreAlarm.value.str					= buf[55]=='1'?"告警":"正常";
				Set_Var_Status(&d->P1CutOffPreAlarm,			  buf[55]=='1'?Alarm:Normal, NULL);
				d->BatteryReplaceWarn.value.str					= buf[56]=='1'?"告警":"正常";
				Set_Var_Status(&d->BatteryReplaceWarn,			  buf[56]=='1'?Alarm:Normal, NULL);
				d->MaintainBypassSwitchOffAlarm.value.str		= buf[58]=='1'?"告警":"正常";
				Set_Var_Status(&d->MaintainBypassSwitchOffAlarm,  buf[58]=='1'?Alarm:Normal, NULL);
				d->MainsFailure.value.str						= buf[60]=='1'?"告警":"正常";
				Set_Var_Status(&d->MainsFailure,		  		  buf[60]=='1'?Alarm:Normal, NULL);
				d->BypassUnstable.value.str						= buf[61]=='1'?"告警":"正常";
				Set_Var_Status(&d->BypassUnstable,		  		  buf[61]=='1'?Alarm:Normal, NULL);
				d->BatteryDischargerOverly.value.str			= buf[64]=='1'?"告警":"正常";
				Set_Var_Status(&d->BatteryDischargerOverly,		  buf[64]=='1'?Alarm:Normal, NULL);
				break;
			default:
				break;
		}
		return 0;
	}
	return 1;
}


/**********************************************************************************************************
* 函数名称： void ups_UPS001_Registration(void)
* 函数说明： UPS监测驱动注册
* 输入参数： 无
* 返回参数： 无
**********************************************************************************************************/
void ups_UPS001_Registration(void)
{
	DeviceRegWithResTimeout(
		"ups",													//设备类型
		"UPS监测",												//设备名称（导航栏默认显示名称）
		"UPS001",												//设备型号
		"适用于UPS三进三出高频机，协议指令为QWS、QWF、QMOD、Q3PV、Q3PC、Q3OV、Q3OC、Q3YV、Q3YC、Q3LD",//驱动描述
		var_attr,												//变量属性声明
		sizeof(Data_Struct),									//变量结构体空间大小
		cmd_fun,												//发送指令生成函数
		parse_fun,												//数据解析函数
		1000													//设备响应超时时间
	);

#if 0 || VirtualFrameEN
	#define	CMD1	"QWS\r"
	#define	RSP1	"(1111111111111111111111111111111111111111111111111111111111111111\r"
	#define	CMD2	"QMOD\r"
	#define	RSP2	"(C\r"
	#define	CMD3	"Q3PV\r"
	#define	RSP3	"(220.2 215.3 222.1 381.4 373.2 384.6\r"		
	#define	CMD4	"Q3PC\r"
	#define	RSP4	"(045.2 044.3 045.1\r"		
	#define	CMD5	"Q3OV\r"
	#define	RSP5	"(220.2 215.3 222.1 381.4 373.2 384.6\r"		
	#define	CMD6	"Q3OC\r"
	#define	RSP6	"(045.2 044.3 045.1\r"		
	#define	CMD7	"Q3YV\r"
	#define	RSP7	"(220.2 215.3 222.1 378.5 379.0 380.2\r"		
	#define	CMD8	"Q3YC\r"
	#define	RSP8	"(045.2 044.3 045.1\r"	
	#define	CMD9	"Q3LD\r"
	#define	RSP9	"(045.2 042.3 047.0 050.1\r"		
	#define	CMD10	"QBV\r"
	#define	RSP10	"(384.0 32 32 100 1000\r"
	#define	CMD11	"QNBV\r"
	#define	RSP11	"(384.0 32 32 100 1000\r"

	VirtualFrameRegistration(CMD1, sizeof(CMD1)-1, RSP1, sizeof(RSP1)-1);
	VirtualFrameRegistration(CMD2, sizeof(CMD2)-1, RSP2, sizeof(RSP2)-1);
	VirtualFrameRegistration(CMD3, sizeof(CMD3)-1, RSP3, sizeof(RSP3)-1);
	VirtualFrameRegistration(CMD4, sizeof(CMD4)-1, RSP4, sizeof(RSP4)-1);
	VirtualFrameRegistration(CMD5, sizeof(CMD5)-1, RSP5, sizeof(RSP5)-1);
	VirtualFrameRegistration(CMD6, sizeof(CMD6)-1, RSP6, sizeof(RSP6)-1);
	VirtualFrameRegistration(CMD7, sizeof(CMD7)-1, RSP7, sizeof(RSP7)-1);
	VirtualFrameRegistration(CMD8, sizeof(CMD8)-1, RSP8, sizeof(RSP8)-1);
	VirtualFrameRegistration(CMD9, sizeof(CMD9)-1, RSP9, sizeof(RSP9)-1);
	VirtualFrameRegistration(CMD10, sizeof(CMD10)-1, RSP10, sizeof(RSP10)-1);
	VirtualFrameRegistration(CMD11, sizeof(CMD11)-1, RSP11, sizeof(RSP11)-1);
#endif		
}

